package websocket.util;

public class Test {
    public static void main(String[] args) {
//        String needData = "AA A5 55 04 03 FE FF 05 04 FE FF 00 03 02 FF FF 04 03 FF FF 05 04 FF FF 03 02 FF FF D3";

//        String needData = "AA A5 55 04 03 02 00 05 04 03 00 00 03 02 00 00 04 03 00 00 05 04 00 00 03 02 00 00 D3";

        String needData = "AA 44 12 1C 2A 00 00 01 48 00 00 00 18 A0 A9 08 FC 51 36 17 81 DE 59 00 36 00 12 00 00 00 00 00 10 00 00 00 08 0F B0 07 E9 09 37 40 17 2A D2 E8 55 57 5C 40 00 00 00 47 5E 68 15 40 C1 00 CE C0 3D 00 00 00 19 F9 8E 3F B7 D0 6F 3F 19 8D 37 40 00 00 00 00 00 00 00 00 00 00 00 00 33 1C 1C 19 00 06 03 D3 C9 AE B0 6C";
        String[] sixteenArr = needData.split(" ");
        // 3-6
        // 0xfe & 0x10    ==>  11111110 & 10000000 = 10000000
//        boolean negative = false;
//        if ((Integer.valueOf(sixteenArr[6],16).byteValue() & 0x10) == 0x10) {
//            negative = true;
//        }
//        if (negative) {
        System.err.println(Integer.valueOf("FE", 16).byteValue());
        int b = (0xff000000 & (Integer.valueOf(sixteenArr[6], 16).byteValue() << 24))
                | (0xff0000 & (Integer.valueOf(sixteenArr[5], 16).byteValue() << 16))
                | (0xff00 & (Integer.valueOf(sixteenArr[4], 16).byteValue() << 8))
                | (0xff & Integer.valueOf(sixteenArr[3], 16).byteValue());
        System.err.println(b);
        System.err.println(b << 1);
//        }

//
//        int a = 0xff000000;
//        System.err.println(a);

        int a = 0xff;

        jieXi(sixteenArr);

    }

    private static void jieXi(String[] sixteenArr) {
        int b = (0xff000000 & (Integer.valueOf(sixteenArr[6], 16).byteValue() << 24))
                | (0xff0000 & (Integer.valueOf(sixteenArr[5], 16).byteValue() << 16))
                | (0xff00 & (Integer.valueOf(sixteenArr[4], 16).byteValue() << 8))
                | (0xff & Integer.valueOf(sixteenArr[3], 16).byteValue());
        System.err.println(b);
    }

    /*
指令发送，14字节，和校验，参照上述表格指令格式。
*/
//    public void action2(char id, unsigned int canshu1, unsigned int canshu2, char dir) {
//        int temp, i;
//        char sum = 0x00;
//
//        String[] sendSixTeen = new String[20];
//        sendSixTeen[0] = "AA";
//        sendSixTeen[1] = "AA";
//        sendSixTeen[2] = "AA";
//        sendSixTeen[0] = "AA";
//        chsend[0] = 0xAA;
//        chsend[1] = 0xA5;
//        chsend[2] = 0x55;
//
//        chsend[3] = id;
//
//        Translate.aa = canshu1;
//
//        for (i = 0; i < 4; i++) {
//            chsend[i + 4] = Translate.bb[i];
//        }
//
//
//        chsend[8] = dir;
//
//
//        Translate.aa = canshu2;
//        for (i = 0; i < 4; i++) {
//            chsend[i + 9] = Translate.bb[i];
//        }
//
//
//        chsend[13] = 0;
//        for (i = 0; i < 13; i++) {
//            sum += chsend[i];
//        }
//        chsend[13] = sum;
//        m_port.WriteToPort(chsend, 14);
//
//    }
}
